/**
 * 
 */
define(function(require, exports, module){
	
	var $ = require('jquery');
	require('tinymce/4.0.10/tinymce.min.js');
	require('jquery/jquery-file-upload/8.8.5/vendor/jquery.ui.widget.js');
	require('jquery/jquery-file-upload/8.8.5/jquery.iframe-transport.js');
	require('jquery/jquery-file-upload/8.8.5/jquery.fileupload.js');
	
	$('#fileupload').fileupload({
        url: "http://localhost:8088/mercy/common/attachment/upload/multi",
        dataType: 'json',
        formData: {uid: '2'},
        acceptFileTypes: /(\.|\/)(gif|png)$/i,
        maxNumberOfFiles : 1,
        maxFileSize: 5000000,
        done: function (e, data) {

            $.each(data.result, function (index, file) {
            	var url = 'http://localhost:8088/mercy/common/attachment/download/'+file.id+'/150x100';
            	console.log(url);
            	$('.mce-btn').parent().find('.mce-textbox').val(url);
            });
        }
    });
	
	tinymce.init({
		selector : 'textarea#editor',
		theme : "modern",
		plugins: ["preview image code table contextmenu"],
		language:'zh_CN',
		file_browser_callback: function(field_name, url, type, win) {
	        if(type=='image') {
	        	$('#fileupload').click();
	        }
	    }
	});
	
	$(".test-click").click(function(){
		var ed = tinyMCE.get('editor');
		alert(ed);
	    ed.setProgressState(1); 
	    $("#description").text(ed.getContent());

	    // Do you ajax call here, window.setTimeout fakes ajax call
	    ed.setProgressState(1); // Show progress
	    window.setTimeout(function() {
	        ed.setProgressState(0); // Hide progress
	        $("#test-area").html(ed.getContent());
	    }, 2000);
	});
	
});